package com.lagou.edu.controller;

import com.lagou.edu.constant.RequestConstant;
import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author srh
 * @date 2020/03/20
 **/
@Controller
@RequestMapping(value = "/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping(value = "/findAll")
    public ModelAndView findAll(ModelAndView modelAndView) {
        modelAndView.setViewName(RequestConstant.TABLE);
        modelAndView.addObject(RequestConstant.DATA, resumeService.findAll());
        return modelAndView;
    }

    @RequestMapping(value = "/delete")
    public ModelAndView delete(ModelAndView modelAndView, Long id) {
        resumeService.delete(id);
        return findAll(modelAndView);
    }

    @RequestMapping(value = "/insert")
    public ModelAndView insert(ModelAndView modelAndView) {
        modelAndView.setViewName(RequestConstant.ADD);
        return modelAndView;
    }

    @RequestMapping(value = "/save")
    public ModelAndView save(ModelAndView modelAndView, Resume resume) {
        resumeService.insert(resume);
        return findAll(modelAndView);
    }

    @RequestMapping(value = "/queryById")
    public ModelAndView queryById(ModelAndView modelAndView, Long id) {
        Resume resume = resumeService.queryById(id);
        modelAndView.addObject(RequestConstant.DATA, resume);
        modelAndView.setViewName(RequestConstant.ADD);
        return modelAndView;
    }
}
